package com.manshutingyu.common.core.exception;

import com.manshutingyu.common.core.dto.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


/**
 * 全局异常处理器
 *
 * @author yinyuxia
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 处理自定义异常
     */
    @ExceptionHandler(BusinessException.class)
    public <T> R<T> handleApiException(BusinessException e) {
        log.error("自定义ApiException 抛出:", e);
        return R.error(e.getCode(), e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public <T> R<T> handleException(Exception e) {
        log.error(e.getMessage(), e);
        return R.error();
    }

}
